package com.lhkj.ct.meta.modules.scheduling.model.dto;

import com.lhkj.ct.base.validator.constraints.HasNonElement;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

/**
  * <p>
  *     描述：新增排班
  * </p>
  */
@Setter
@Getter
public class ScheduleDto implements Serializable {

    @NotNull(message = "请选择开始日期")
    @ApiModelProperty(value = "开始日期")
    private LocalDate startDate;

    @NotNull(message = "请选择截止日期")
    @ApiModelProperty(value = "截止日期")
    private LocalDate endDate;

    @NotNull(message = "排除规则不能为null")
    @ApiModelProperty(value = "排除周几,使用数字1~7", example = "[6,7]", notes = "1 ~ 7")
    private Set<Integer> excludes;

    @NotEmpty(message = "请选择排班医生")
    @HasNonElement(message = "排班医生不能含有null选项")
    @ApiModelProperty(value = "排班医生")
    @Valid
    private List<SchedulingDoctor> schedulingDoctors;

    @NotEmpty(message = "请至少设置一个排班时间段和号源")
    @HasNonElement(message = "排班时间段和号源不能含有null选项")
    @ApiModelProperty(value = "排班时间段和号源")
    @Valid
    private List<SchedulingTime> schedulingTimes;

    public List<SchedulingTime> getSchedulingTimes() {
        schedulingTimes.sort(Comparator.comparing(SchedulingTime::getStart));
        return schedulingTimes;
    }
}
